-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: properly remove temporary files leftover after running tests #1762
Conversation
68d7088
to
8c82df7
Compare
if std::fs::remove_dir(cache_dir.path()).is_ok() && cache_dir.path().exists() { | ||
let _ = cache_dir.close(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that I understand putting cache_dir.close()
behind an if
. fs::remove_dir
will return Ok
if cache_dir
contains no files and is successfully removed (which would cause cache_dir.path().exists()
to be false
), or it will return an Err
if cache_dir
contains files.
Would something like the following also work without putting tempdir closing behind an if
statement?
if std::fs::remove_dir(cache_dir.path()).is_ok() && cache_dir.path().exists() { | |
let _ = cache_dir.close(); | |
} | |
let _ = std::fs::remove_dir_all(cache_dir.path()); | |
let _ = cache_dir.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure I tried that and it didn't work (would sometimes error on the second line).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you can find a different way to solve it, it would be appreciated. The goal is just for it to 1) not cause an error, and 2) be gone after the run. Took me a while to get that going and I agree it's weird (but works).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that is weird. If you've already tried alternatives to the if
and the tests' temp-files weren't fully removed, then the PR looks good to me.
8c82df7
to
c8b4744
Compare
Take 2: It took a while to track down which tests were leaving around .tmp* directories and files in the TEMPDIR after the test suite was run, but it appears that this resolves them all across normal and 'ignored' tests.
In short, if there are any open files/dirs remaining when TempDir is scoped out, a deletion is silently omitted. This code more explicitly cleans up some temporary artifacts in order to ensure everything is removed and closed before that happens.